package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.Appointment;
import cn.xgj.sfzy.entity.Consult;
import cn.xgj.sfzy.mapper.AppointmentMapper;
import cn.xgj.sfzy.mapper.ConsultMapper;
import cn.xgj.sfzy.service.AppointmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AppointmentServiceImpl
 * @Description TODO
 * @Author furuyue
 * @Date 2024年10月23日 20:11
 * @Version 1.0
 */

@Service
public class AppointmentServiceImpl implements AppointmentService {

    @Autowired
    private AppointmentMapper appointmentMapper;
    @Autowired
    private ConsultMapper consultMapper;

    @Override
    public int remove(Integer id) {
        return appointmentMapper.delete(id);
    }

    public int edit(Appointment appointment) {
        return appointmentMapper.update(appointment);
    }

    @Override
    public List<Appointment> findAll(Appointment appointment) {
        return appointmentMapper.find(appointment);
    }

    public PageInfo<Appointment> findByPage(Integer pageNum, Integer pageSize, Appointment appointment) {
        PageHelper.startPage(pageNum,pageSize);
        List<Appointment> list = appointmentMapper.find(appointment);
        PageInfo<Appointment> info = new PageInfo<Appointment>(list);
        return info;
    }

    @Override
    public List<Appointment> findByUSerId(Integer userId) {
        List<Appointment> list = appointmentMapper.findByUserId(userId);
        for(Appointment a :list){
            Long consultId = a.getConsultId();
            Consult consult = consultMapper.selectById(consultId.intValue());
            a.setConsult(consult);
        }
        return list;
    }

}
